package com.csxh.bean;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

import com.csxh.util.StringUtil;

public class RequestParams {

	private Map<String, Object> map;

	public RequestParams(Map<String, String[]> paramsMap) {
		super();
		this.map = new HashMap<String, Object>();
		
		for (Map.Entry<String, String[]> entry : paramsMap.entrySet()) {
			String[] ss=entry.getValue();
			if (null!=ss) {
				if (ss.length==1) {
					Object value=StringUtil.toObjectfrom(ss[0], Object.class);
					this.map.put(entry.getKey(), value);
				}
				Object[] values=new Object[]{ss.length};
				for (int i = 0; i < values.length; i++) {
					Object value=StringUtil.toObjectfrom(ss[i], Object.class);
					values[i]=value;
				}
				this.map.put(entry.getKey(), values);
			}
		}

	}
	
	public<T> T get(String key,T defaultValue) {
		Object value=this.map.get(key);
		return null==value ? defaultValue : (T)value;
	}
	
	public Map<String, Object> getMap() {
		
		return this.map;
	}

	@Override
	public String toString() {
		return this.map.toString();
	}
	
	

}
